﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Streams;

namespace Password.Recursos
{
    class File
    {
        /// <summary>
        /// Grava um arquivo no LocalFolder e se arquivo ja existir substitui
        /// </summary>
        /// <param name="Nome">Nome do arquivo que sera gravado no LocalFolder</param>
        /// <param name="Conteudo">O conteudo que sera gravado no Aqruivo</param>
        private async void SalvarArquivo(string Nome, string Conteudo)
        {
            StorageFolder folder = ApplicationData.Current.LocalFolder;
            StorageFile file = await folder.CreateFileAsync(Nome, CreationCollisionOption.ReplaceExisting);
            byte[] cont = Encoding.UTF8.GetBytes(Conteudo);

            using (IRandomAccessStream writeStream = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                using (DataWriter dataWriter = new DataWriter(writeStream))
                {
                    dataWriter.WriteBytes(cont);
                    await dataWriter.StoreAsync();
                    await dataWriter.FlushAsync();
                }
            }
        }
    }
}
